<template>
    <div class="page-title">赠送查询</div>
    <el-form class="search-form" inline :model="searchForm">
        <div>
            <el-form-item class="search-form-item" label="桌台号:">
                <el-input v-model="searchForm.roomName" placeholder="请选择桌台号" @click="allTableSelectShow = true" clearable />
            </el-form-item>
            <el-form-item class="search-form-item" label="台单号:">
                <el-input v-model="searchForm.consumeCode" clearable placeholder="请输入台单号" />
            </el-form-item>
            <el-form-item class="search-form-item" label="赠送人:">
                <el-select v-model="searchForm.giftUser" filterable clearable>
                    <el-option v-for="item in waiter_options" :key="item.userCode" :value="item.userCode"
                        :label="item.userName" />
                </el-select>
            </el-form-item>
            <el-form-item class="search-form-item" label="赠送时间:">
                <el-date-picker v-model="searchForm.operDate" type="datetimerange" start-placeholder="开始时间"
                    end-placeholder="结束时间" value-format="YYYY-MM-DD HH:mm:ss" clearable />
            </el-form-item>

            <el-form-item class="action-btn-box">
                <el-button type="primary" @click="handleSearch">查询</el-button>
                <el-button class="reset-btn" @click="handleReset">清空筛选</el-button>
            </el-form-item>
        </div>
    </el-form>
    <div class="table-box">
        <el-table :data="tableData" stripe v-loading="loading">
            <el-table-column prop="consumeCode" label="台单号" min-width="10%"  align="center"/>
            <el-table-column prop="goodsName" label="商品名称" min-width="10%"  align="center"/>
            <el-table-column prop="orderQty" label="数量（单位）" min-width="8%"  align="center"/>
            <el-table-column prop="realAmt" label="单价" min-width="8%"  align="center"/>
            <el-table-column prop="salePrice" label="赠送金额" min-width="8%" align="center">
                <template #default="scope">
                    <span class="color-FF6A00">{{ scope.row.salePrice }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="giftUser" label="赠送人" min-width="8%"  align="center"/>
            <el-table-column prop="giftTime" label="赠送时间" min-width="12%"  align="center"/>
            <!-- <el-table-column prop="" label="赠送类型" min-width="8%"  align="center"/> -->
            <el-table-column prop="roomName" label="桌台" min-width="7%"  align="center"/>
            <el-table-column prop="giftRemark" label="赠送备注" min-width="8%"  align="center"/>
            <el-table-column prop="state" label="状态" min-width="6%"  align="center"/>
            <!-- <el-table-column prop="" label="操作" min-width="16%" fixed="right">
                <template #default="scope">
                    <el-button class="action-btn" @click="handleDetail"> 退款</el-button>
                </template>
            </el-table-column> -->
        </el-table>
    </div>
    <!-- <div class="pagination-box">
        <el-pagination background layout="prev, pager, next,sizes, jumper, total" :total="total" :current-page="currentPage"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" style="margin-top:10px" />
    </div> -->

    <div class="orderRecords-container-footer">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page.sync="currentPage" :page-size="pageSize" layout="total, prev, pager, next,sizes, jumper"
            :total="total">
        </el-pagination>
        <button class="footer-button">确定</button>
    </div>

    <AllTableSelect v-model="allTableSelectShow" @cancel="allTableSelectShow = false" @confirm="selectTable" />
</template>
  
<script setup>
import AllTableSelect from '@/views/components/AllTableSelect.vue' 
import Api from '@/api'
import { transformWorkTime } from '@/utils/chenhao.js' 
import useConfigStore from '@/store/config'  
const configStore = useConfigStore()
const orgStartTime = configStore.shopInfo.orgReportStartTime //orgStartTime
const orgEndTime = configStore.shopInfo.orgReportEndTime //orgEndTime  

// 点击选择桌台
const allTableSelectShow = ref(false)
// 选中桌台
const selectTable = (data) => {
    if (data.name) {
        console.log(data);
        searchForm.value.roomCode = data.code
        searchForm.value.roomName = data.name
        allTableSelectShow.value = false
    } else {
        ElNotification({
            title: '提示',
            message: '请选择桌号',
            type: 'warning',
        })
    }

}

// 获取服务员OPTIONS
let waiter_options = ref([])
const get_waiter_options = (params) => {
    Api.Common.PcObjProcess.Do({ "functionName": "getWaiterList", "orgCode": "0004", "contentData": { parentCode: '571' } }).then(res => {
        console.log('获取服务员OPTIONS res :>> ', res,);
        waiter_options.value = res.result
    })
}
get_waiter_options()

let loading = ref(false)
let searchForm = ref({})
// 搜索
const handleSearch = (params) => {
    currentPage.value = 1;
    getTableData();
}
// 重置
const handleReset = (params) => {
    searchForm.value = {}
    handleSearch()
}
// 查询表格数据
let tableData = ref([{}])
let currentPage = ref(1)
let pageSize = ref(10)
let total = ref(0)
const handleSizeChange = (val) => {
    pageSize.value = val
    getTableData()
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getTableData()
}
const getTableData = (user) => {
    let query = {
        ...searchForm.value,
        pageIndex: currentPage.value,
        pageSize: pageSize.value
    }
    if (query.operDate && query.operDate.length > 1) {
        query.beginTime = query.operDate[0]
        query.endTime = query.operDate[1]
    }
    console.log('查询前的query :>> ', query,);
    loading.value = true
    // return
    Api.Common.PcObjProcess.Do({ "functionName": "GetSignRecordList", "orgCode": "0004", "contentData": query }).then(res => {
        console.log('查询订单table res :>> ', res,);
        loading.value = false
        tableData.value = res.data
        total.value = res.totalCount
    })
}

onMounted(() => {
   searchForm.value.operDate = transformWorkTime('今天', orgStartTime, orgEndTime) // 默认今天
   getTableData()
}) 

// 点击网上支付查询
const handleSearchPay = (params) => {

}

// 点击查看明细
const handleDetail = (params) => {

}

// 点击复台
const handleRe = (params) => {

}

</script>
  
<style scoped lang="scss">
@import '@/styles/com_style_input.css';
/* 在这里编写组件的CSS样式 */
// .app-container {}
::v-deep{
    .el-form-item{
        margin-right: 15px !important;
    }
}
.search-form {
    width: 1520px;
    background: #FFFFFF;
    border-radius: 8px;
    padding: 20px 10px 0 40px;
    margin-bottom: 20px;

    // display: flex;
    .search-form-item {
        ::v-deep {
            .el-form-item__label {
                line-height: 48px;
            }

            .el-date-editor {
                width: 350px;

            }

            .el-input {
                width: 160px;
            }

            .el-input__wrapper {
                height: 40px;
                background: #FAFAFA;
                border-radius: 8px;
            }

            .el-select__wrapper {
                width: 180px;
                height: 40px;
                background: #FAFAFA;
                border-radius: 8px;
            }
        }
    }

    .range-item {
        .el-input {
            width: 130px;
        }
    }

    .action-btn-box {
        float: right;
        padding-right: 18px;
 
        button {
            width: 120px;
            height: 48px;
            line-height: 48px;
            background: #FFE566;
            border-radius: 8px;
            border: 0;
            font-size: 16px;
            color: #212121;
        }

        .reset-btn {
            background: #E6E6E6;
            color: #666666;
        }
    }
}

.table-box {
    padding: 20px 40px;
    background: #FFFFFF;
    border-radius: 8px;
    width: 1520px;
    min-height: 550px;
    .total-box {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 20px;
        color: #212121;
    }
    .el-table--fit {
         height: 400px;
    }

    ::v-deep {
        .el-table__inner-wrapper::before {
            height: 0px;
        }

        .el-table th {
            font-size: 13px;
            font-weight: 700;
        }

        .el-table .el-table__header th,
        .el-table .el-table__header tr,
        .el-table .el-table__header td {
            height: 48px;
            background: #F9F9F9;
        }
    }

    .action-btn {
        width: 66px;
        height: 28px;
        border-radius: 4px;
        border: 1px solid #FF6A00;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 14px;
        color: #FF6A00;
    }
}

.pagination-box {
    margin-top: 20px;

    ::v-deep {
        .number {
            background: #E6E6E6 !important;
            border-radius: 8px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #666666;
        }

        .number:hover {
            color: #FF6A00;
        }

        .is-active {
            background-color: #FF6A00 !important;
            border-radius: 8px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #FFFFFF;
        }

    }
}

.color-FF6A00 {
    color: #FF6A00;
}

.page-title {
    font-family: Microsoft YaHei;
    font-weight: bold;
    font-size: 24px;
    color: #212121;
    margin-bottom: 10px;
}
::v-deep .el-table .cell {
    font-family: Microsoft YaHei;
    font-weight: 400;
    font-size: 0.07292rem;
    color: #666666;
    line-height: 0.07292rem;
}
</style>
  